﻿using System;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace HslCommunication.BasicFramework
{
	/// <summary>
	/// 一个自定义的支持序列化反序列化的异常类，具体用法参照第四版《CLR Via C#》P414
	/// </summary>
	/// <typeparam name="TExceptionArgs">泛型异常</typeparam>
	// Token: 0x02000192 RID: 402
	[Serializable]
	public sealed class Exception<TExceptionArgs> : Exception, ISerializable where TExceptionArgs : ExceptionArgs
	{
		/// <summary>
		/// 消息
		/// </summary>
		// Token: 0x170006AB RID: 1707
		// (get) Token: 0x060020B8 RID: 8376 RVA: 0x0009F644 File Offset: 0x0009D844
		public TExceptionArgs Args
		{
			get
			{
				return this.m_args;
			}
		}

		/// <summary>
		/// 实例化一个异常对象
		/// </summary>
		/// <param name="message">消息</param>
		/// <param name="innerException">内部异常类</param>
		// Token: 0x060020B9 RID: 8377 RVA: 0x0009F65C File Offset: 0x0009D85C
		public Exception(string message = null, Exception innerException = null) : this(default(TExceptionArgs), message, innerException)
		{
		}

		/// <summary>
		/// 实例化一个异常对象
		/// </summary>
		/// <param name="args">异常消息</param>
		/// <param name="message">消息</param>
		/// <param name="innerException">内部异常类</param>
		// Token: 0x060020BA RID: 8378 RVA: 0x0009F67C File Offset: 0x0009D87C
		public Exception(TExceptionArgs args, string message = null, Exception innerException = null) : base(message, innerException)
		{
			this.m_args = args;
		}

		// Token: 0x060020BB RID: 8379 RVA: 0x0009F68F File Offset: 0x0009D88F
		[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
		private Exception(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			this.m_args = (TExceptionArgs)((object)info.GetValue("Args", typeof(TExceptionArgs)));
		}

		/// <summary>
		/// 获取存储对象的序列化数据
		/// </summary>
		/// <param name="info">序列化的信息</param>
		/// <param name="context">流的上下文</param>
		// Token: 0x060020BC RID: 8380 RVA: 0x0009F6BB File Offset: 0x0009D8BB
		[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("Args", this.m_args);
			base.GetObjectData(info, context);
		}

		/// <summary>
		/// 获取描述当前异常的消息
		/// </summary>
		// Token: 0x170006AC RID: 1708
		// (get) Token: 0x060020BD RID: 8381 RVA: 0x0009F6E0 File Offset: 0x0009D8E0
		public override string Message
		{
			get
			{
				string message = base.Message;
				return (this.m_args == null) ? message : (message + " (" + this.m_args.Message + ")");
			}
		}

		/// <summary>
		/// 确定指定的object是否等于当前的object
		/// </summary>
		/// <param name="obj">异常对象</param>
		/// <returns>是否一致</returns>
		// Token: 0x060020BE RID: 8382 RVA: 0x0009F72C File Offset: 0x0009D92C
		public override bool Equals(object obj)
		{
			Exception<TExceptionArgs> exception = obj as Exception<TExceptionArgs>;
			bool flag = exception == null;
			return !flag && object.Equals(this.m_args, exception.m_args) && base.Equals(obj);
		}

		/// <inheritdoc />
		// Token: 0x060020BF RID: 8383 RVA: 0x0009F778 File Offset: 0x0009D978
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		/// <summary>
		/// 用于反序列化的
		/// </summary>
		// Token: 0x040007BD RID: 1981
		private const string c_args = "Args";

		// Token: 0x040007BE RID: 1982
		private readonly TExceptionArgs m_args;
	}
}
